//
//  MovieScrollView.m
//  Movie
//
//  Created by cjy on 16/3/23.
//  Copyright © 2016年 HY. All rights reserved.
//

#import "MovieScrollView.h"
#import "MovieImageView.h"
#import "MovieModel.h"
#import <UIImageView+WebCache.h>

#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height


@interface MovieScrollView ()


@property (nonatomic ,assign ,readwrite) NSInteger currentIndex;
@end


@implementation MovieScrollView
- (instancetype)initWithFrame:(CGRect)frame imageArray:(NSArray *)imageArray index:(NSInteger)index{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.contentSize = CGSizeMake(imageArray.count * [UIScreen mainScreen].bounds.size.width, 0);
//
        self.bounces = NO;
//
        self.pagingEnabled = YES;
//
        self.contentOffset = CGPointMake(index * [UIScreen mainScreen].bounds.size.width, 0);

        for (int i = 0; i < imageArray.count; i ++) {
       
            MovieImageView *img = [[MovieImageView alloc]initWithFrame:CGRectMake(i *kWidth, 0, kWidth, kHeight) width:35 model:imageArray[i] collor:[UIColor whiteColor]];
            
            MovieModel *model = [[MovieModel alloc]init];
            
            model = imageArray[i];

            [img.picture sd_setImageWithURL:[NSURL URLWithString:model.coverForDetail] placeholderImage:nil];
            
            [self addSubview:img];
        }
        
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
